package com.hp.auth_service.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hp.auth_service.entity.RoleFun;
import com.hp.auth_service.service.IRoleFunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
public class RoleFunctionsController {

    @Autowired
    private IRoleFunService roleFunService;

    @PostMapping("/role-functions")
    public ResponseEntity<RoleFun> addRoleFunctions(@RequestBody RoleFun roleFun){
        roleFunService.save(roleFun);
        //考虑是上级权限的情况
        return ResponseEntity.ok(roleFun);
    }

    @DeleteMapping("/role-functions/{roleId}/{functionsId}")
    public ResponseEntity<RoleFun> deleteRoleFunctions(@PathVariable String roleId, @PathVariable String functionsId){
        roleFunService.remove(new QueryWrapper<RoleFun>()
                .lambda()
                .eq(RoleFun::getRoleId,roleId)
                .eq(RoleFun::getFunId,functionsId));
        //考虑是上级权限的情况
        return ResponseEntity.ok(null);
    }
}
